import sys

from PySide6.QtCore import Qt
from PySide6.QtGui import QPixmap, QPen, QPainter, QColor
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.last_x = None
        self.last_y = None

        self.label = QLabel()
        self.canvas = QPixmap(400, 300)
        self.canvas.fill(Qt.white)

        self.setCentralWidget(self.label)
        self.setFixedSize(400, 300)

    def mouseMoveEvent(self, e):
        if self.last_x is None:
            self.last_x = e.x()
            self.last_y = e.y()
            return

        painter = QPainter(self.canvas)
        painter.setRenderHint(QPainter.Antialiasing)
        pen = QPen()
        pen.setWidth(3)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)
        painter.setPen(pen)
        painter.drawLine(self.last_x, self.last_y, e.x(), e.y())
        painter.end()

        self.label.setPixmap(self.canvas)

        self.last_x = e.x()
        self.last_y = e.y()

    def mouseReleaseEvent(self, event):
        self.last_x = None
        self.last_y = None

app = QApplication(sys.argv)
window = MainWindow()
window.setMouseTracking(True)
window.show()
app.exec()